<!DOCTYPE html>
<html>
<head>
    <title>二维码解析</title>
    <meta charset="utf-8">
    <script src="llqrcode.js" type="text/javascript"></script>
</head>
<body>
    <h3>解析二维码</h3>
    <div>
        <input type="file" name="" id='img'>
    </div>
</body>
<script type="text/javascript">
    //获取预览图片路径
    var getObjectURL = function(file){
        var url = null ; 
        if (window.createObjectURL!=undefined) { // basic
            url = window.createObjectURL(file) ;
        } else if (window.URL!=undefined) { // mozilla(firefox)
            url = window.URL.createObjectURL(file) ;
        } else if (window.webkitURL!=undefined) { // webkit or chrome
            url = window.webkitURL.createObjectURL(file) ;
        }
        return url ;
    }
    // 解析二维码
    var qrcode_decode = function (){
        // file上传的二维码图片文件
        var src = document.querySelector('#img').files[0];
        // qrcode.decode接受图片路径
        qrcode.decode(getObjectURL(src));
        qrcode.callback = function( imgMsg ){
            console.log("图片信息", imgMsg);
            alert(imgMsg);
        }
    }
    // 事件
    var input = document.querySelector('#img');
    if (input.addEventListener) {
        input.addEventListener('change', function(){
            qrcode_decode();
        });
    } else {
        input.attachEvent('onchange', function(){
            qrcode_decode();
        });
    }
</script>
</html>